<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@include file="/common/definition.jsp"%>

<html:html>
<tiles:insert beanName="admin-definition" flush="true">
	<tiles:put name="title"> Administrator Management </tiles:put>
	<tiles:put name="body" type="string">
	<div class="mainHome col-md-12" style="padding: 25px; min-height: 360px">
		<div class="row">
			<div class="col-md-3">
				<div class="muted h3" style="padding-bottom: 15px;">Danh Mục</div>
				<div class="dropdown clearfix">
					<ul class="dropdown-menu"
						style="display: block; position: static; margin-bottom: 5px; *width: 180px;">
						<s:iterator value="productModel.listSubcat" id="list">
							<li class="dropdown-submenu"><a><s:property
										value="mainCatName" /> </a>
								<ul>
									<s:iterator value="listinfo" id="list1">
										<li><s:a action="viewCategories">
												<s:property value="catName" />
												<s:param name="catID" value="catID"></s:param>
											</s:a></li>
									</s:iterator>
								</ul>
							</li>
						</s:iterator>
					</ul>
				</div>
			</div>
			<div class="col-md-5">
			<div class="muted h3" style="padding-bottom: 10px;">Chỉnh sửa danh mục</div>
				<div class="col-sm-12" style="padding: 0px;">
					<div class="error_box"></div>
				</div>
				<s:form name="editCategory" action="editCategories" theme="simple">
					<s:if test="errorAddCat == null || errorAddCat == ''">
					</s:if>
					<s:elseif test="errorAddCat == 'Thay đổi chi tiết danh mục thành công'">
						<div class="success_box" style="display: block;"><s:property value="errorAddCat" /></div>
					</s:elseif>
					<s:elseif test="errorAddCat != null">
						<div class="error_box" style="display: block;"><s:property value="errorAddCat" /></div>
					</s:elseif>
					<div class="form-group">
						<label class="contact"><strong>Danh Mục ID:</strong> </label>
						<s:textfield name="categories.catID" cssClass="form-control"
							disabled="true"></s:textfield>
					</div>
					<div class="form-group">
						<label class="contact"><strong>Tên Danh Mục:</strong> </label>
						<s:textfield name="categories.catName" cssClass="form-control"
							data-toggle="tooltip" 
							title="Tên danh mục có độ dài từ 6 đến 20 ký tự"></s:textfield>
					</div>
					<div class="form-group">
						<label class="contact"><strong>Danh Mục:</strong> </label> 
						<select name="categories.mainCatID" class="form-control" tabindex="0">
							<s:if test="categories.catID != null || productModel.categories.catID != null">
								<s:iterator value="productModel.listMainCategories">
									<s:if test="mainCatID == categories.mainCatID">
										<option value='<s:property value="mainCatID"/>'
											selected="selected">
											<s:property value="mainCatName" />
										</option>
									</s:if>
									<s:else>
										<option value='<s:property value="mainCatID"/>'>
											<s:property value="mainCatName" />
										</option>
									</s:else>
								</s:iterator>
							</s:if>
						</select>
					</div>
					<div class="pull-right">
						<button class="btn btn-primary">Sửa</button>
						<button type="reset" class="btn btn-default">Nhập Lại</button>
					</div>
				</s:form>
				<script type="text/javascript">
				var validator = new FormValidator('editCategory', 
				[{
					name: 'categories.catName',  
					display: 'tên danh mục',
					rules: 'required|min_length[6]|max_length[20]'
				},{
					name: 'categories.mainCatID',  
					display: 'danh mục',
					rules: 'is_natural'
				}], function(errors, evt) {
							var SELECTOR_ERRORS = $('.error_box'),
							SELECTOR_SUCCESS = $('.success_box');
							
						if (errors.length > 0) {
							SELECTOR_ERRORS.empty();
							for (var i = 0, errorLength = errors.length; i < errorLength; i++) {
								SELECTOR_ERRORS.append(errors[i].message + '<br />');
							}
							
							SELECTOR_SUCCESS.css({ display: 'none' });
							SELECTOR_ERRORS.fadeIn(200);
						} else {
							SELECTOR_ERRORS.css({ display: 'none' });
							SELECTOR_SUCCESS.fadeIn(200);
						}			
					});
				</script>
			</div>
		</div>
	</div>
	</tiles:put>
</tiles:insert>
</html:html>

<script type="text/javascript">
	function switchAction(formId, action) {
		$('#' + formId).attr('action', action);
		$.post(action);
	}
</script>
